package com.project.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.project.ds.ActivityGuestMapper;
import com.project.ds.ActivityMapper;
import com.project.entity.activity.Activity;
import com.project.entity.activity.ActivityGuest;
import com.project.service.IActivityService;

/**
 * 活动实体类查询服务接口实现类
 * @author chenlz
 *
 */
@Service
@Transactional//后面配置具体的数据源的名称。例如：@Transactional(value="dataSourceTransactionManagerZnwlOrder")
public class ActivityServiceImpl implements IActivityService {
	
	@Autowired
	private ActivityMapper activityMapper;
	
	@Autowired
	private ActivityGuestMapper activityGuestMapper;
	
	/**
	 * 获取不带分页的数据
	 * @param activity
	 * @return
	 */
	@Override
	public List<Activity> queryAllList(Activity activity) {
		return activityMapper.queryAllList(activity);
	}
	
	/**
	 * 查询所有
	 * @param activity
	 * @return
	 */
	@Override
	public List<Activity> queryList(Activity activity, int pageSize, int pageNo) {
		return activityMapper.queryList(activity, pageSize, pageNo);
	}
	
	/**
	 * 根据ID获取activityDto数据
	 * @param activityDtoId
	 * @return
	 */
	@Override
	public Activity queryById(Long activityDtoId, Long userId) {
	    Activity activity;
		if(userId==null){
		    activity = activityMapper.findActivityById(activityDtoId);
		}else{
		    activity = activityMapper.queryById(activityDtoId, userId);
		}
		List<ActivityGuest> activityGuestList = activityGuestMapper.queryByActivityId(activityDtoId);
		if(activity!=null){
		    activity.setActivityGuestList(activityGuestList);
		}
		return activity;
	}
	
	/**
	 * 查询总条数
	 * @param activity
	 * @return
	 */
	public int queryCount(Activity activity) {
		return activityMapper.queryCount(activity);
	}
	
	/**
	 * 获取带分页的数据
	 * @param activity
	 * @param pageSize
	 * @param pageNo
	 * @return
	 */
	@Override
	public List<Activity> queryPageData(Activity activity, int pageSize, int pageNo) {
		return activityMapper.queryPageData(activity, pageSize, pageNo);
	}
	
	/**
	 * 保存
	 * @param activity
	 * @return
	 */
	@Override
	public Long save(Activity activity) {
		activityMapper.insert(activity);
		return activity.getId();
	}
	
	/**
	 * 修改
	 * @param activity
	 * @return
	 */
	public void edit(Activity activity) {
		activityMapper.update(activity);
	}
	
	/**
	 * 删除
	 * @param activityDtoId
	 */
	public void deleteById(Long activityDtoId) {
		activityMapper.deleteById(Activity.class, activityDtoId);
	}

	@Override
	public Activity getById(Long id) {
		return activityMapper.findById(Activity.class, id);
	}
	
}
